package com.study.tests;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.study.utils.SortedListOf;
import static com.study.tests.ContactDataGenerator.loadContactsFromXmlFile;
import static com.study.tests.ContactDataGenerator.loadContactsFromCsvFile;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;


public class ContactCreationTest extends TestBase {

	@DataProvider
	public Iterator<Object[]> contactsFromFile() throws IOException {
		return wrapContactDataForDataProvider(loadContactsFromXmlFile(new File("contacts.xml"))).iterator();
	}
	
	@Test(dataProvider = "contactsFromFile")
	public void testContactCreationWithValidData(ContactData contact)
			throws Exception {
		// save old state
		SortedListOf<ContactData> oldList = app.getContactHelper().getContacts();

		// actions
		app.getContactHelper().createContact(contact);
		
		// save new state
		SortedListOf<ContactData> newList = app.getContactHelper().getContacts();

		// compare state
		assertThat(newList, equalTo(oldList.withAdded(contact)));
	}
}